<template>
	<view class="mainpadding2 beijingse">
		<view class="flexbetween flex_wrap ">
			<view class="spbox margin_top" v-for="item in list.data" :key="item.id" @click="tzsoxq(item.id)">
				<image class="sptp" :src="item.image_text" mode=""></image>
				<view class="" style="padding: 30rpx 15rpx;">
					<view class="ershiba xiaohei yhxk">{{item.name}}</view>
					<view class="strongtext xiaocheng margin_top">￥
						<text class="sanshier xiaocheng ">{{item.price}}</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				type: 1,//1医疗，2礼品
				page: 1,
				limit: 12,
				list: {
					data: []
				},
			}
		},
		onLoad(options) {
			this.type = options.id
			let text = ""
			if (this.type == 2) {
				text = "礼品列表"
			} else if (this.type == 1) {
				text = "医疗服务"
			}
			uni.setNavigationBarTitle({
				title: text
			});
			this.init()
		},
		methods: {
			tzsoxq(id) {
				uni.navigateTo({
					url: '/pages_homepage/shangpinxq?id='+id
				})
			},
			init(isPage, page) {
				let _this = this
				httpRequest.request('/api/goodscl/goodsIndex', 'GET', {
					page: page || 1,
					limit: _this.limit,
					data_type:this.type,
				}).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
		}
	}
</script>

<style lang="scss" scoped>
	.spbox {
		width: 48%;
	}

	.sptp {
		width: 338rpx;
		height: 338rpx;
		border-radius: 11rpx 11rpx 0 0;
	}

	.spbox {
		background: #FFFFFF;
		border-radius: 11rpx 11rpx 11rpx 11rpx;
	}
</style>